<?php

namespace App\Jobs;

use App\Helpers\BaseData;
use App\Models\Car;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class LeaseTime implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels,BaseData;

    /**
     * Create a new job instance.
     *
     * @return void
     */

    public function __construct()
    {
        //
       // info('超时任务');

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $data = Car::query()->where('non_lease_time','<',now())->pluck('id');
        try{
            DB::beginTransaction();
            if($data){
                Car::query()->whereIn('id',$data)->update(['non_lease_time'=>null,'non_lease_date'=>null]);
            }
            DB::commit();

        }catch (\Exception $e){
            DB::rollBack();
        }

    }

}
